
$(function() {
	$('#date').datepicker(_date1_option);
	$('#date1').datepicker(_date1_option);
	$('#date2').datepicker(_date1_option);
	
	Tip.emp('负责人');
	
	$('#currency').change(function() {
		_from();
	});
	
	$('#amount').keyup(function() {
		_from();
				
		_cal();
	});
	
	$('#yield').change(function() {
		_cal();
	});
	
	$('#date1').change(function() {
		_cal();
	});
	
	$('#date2').change(function() {
		_cal();
	});
	
	$('#day_t').change(function() {
		var s = $(this).val();
		if (s != null && s != '-')　{
			$('#day').val(s);
		}
		
		_day();
	});
	
	$('#day').change(function() {
		_day();
	});
		
	$('textarea').css("width", 400);
});

function _day() {
	var t1 = $('#date1').val();
	var dd = $('#day').val();
		
	t1 = t1.replace(/\-/g, "/");
	
	var date = new Date(t1);
	date.setDate(date.getDate() + parseInt(dd));
	
	var dt = $.dateFormat.date(date, "yyyy-MM-dd");
	var t1 = $('#date2').val(dt);
    // alert(dt);
	
	_cal();
}

function _from() {
	var a = $("#amount").val();
	var b = $("#currency").find("option:selected").text();
	Currency.upper(a, b, "#label_amount");
}

function _bonus() {
	var a = $("#bonus").val();
	var b = $("#currency").find("option:selected").text();
	Currency.upper(a, b, "#label_bonus");
}

function _cal() {
	var t1 = $('#date1').val();
	// alert(t1);
	if (t1 == undefined || t1 == '') {
		return;
	}
	
	var t2 = $('#date2').val();
	// alert(t2);
	if (t2 == undefined || t2 == '') {
		return;
	}
	
	var day = GetDateDiff(t1, t2, "day");
	if (day <= 0) {
		return ;
	}
	
	$('#day').val(day);
	
	var a = $("#amount").val();
	// alert(a);
	if (a == undefined || a == '') {
		return;
	}
	
	var b = $('#yield').val();
	// alert(b);
	if (b == undefined || b == '') {
		return;
	}
			 
	var c = fxmul(a, b);
	var t = fxmul(c, day) / 36500;
	
	t  = fmoney(t, 2);
	t = t.replace(/,/g, '');
	
	$('#bonus').val(t);
	
	_bonus();
}
